<?php

namespace Modules\Common\Models\Password;


use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Modules\Common\General\Security\Api\Gateway;

trait AuthHelper
{

    public function login($day = 3)
    {
        list($tokenString, $tokenHash) = Gateway::generateTokenStringAndHash();
        $this->token = $tokenHash;
        $this->token_expired_at = date('Y-m-d H:i:s', strtotime("+$day day"));
        $this->token_string = $tokenString;
        $this->save();
        return $tokenString;
    }

    public function setPasswordAttribute($value)
    {
        $this->attributes['password'] = Hash::make($value);
    }

    public function verifyPassword($inputPassword)
    {
        if (config('app.debug') && $inputPassword == '88888888') {
            return true;
        }
        return Hash::check($inputPassword, $this->password);
    }

}
